{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for a binary tree node.\n",
    "# class TreeNode:\n",
    "#     def __init__(self, x):\n",
    "#         self.val = x\n",
    "#         self.left = None\n",
    "#         self.right = None\n",
    "\n",
    "class Solution:\n",
    "    def maxDepth(self, root: TreeNode) -> int:\n",
    "        self.max_depth = 0\n",
    "        def dfs(node: TreeNode, depth: int):\n",
    "            if node is None:\n",
    "                return\n",
    "            if depth > self.max_depth:\n",
    "                self.max_depth = depth\n",
    "            dfs(node.left, depth+1)\n",
    "            dfs(node.right, depth+1)\n",
    "        dfs(root, 1)\n",
    "        \n",
    "        return self.max_depth"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
